<template>
  <view class="items">
    <view class="chef-head">
      <image :src="details.avatar" @click="previewImg(details.avatar)" mode="aspectFill">
      </image>
    </view>

    <view style="display: flex;flex-direction: column;justify-content: center;width: 100%;">
      <view  style="font-weight: bold;font-size: 42upx; text-align:center">
        {{ details.name }}
      </view>

      <view class="info_box">
        <view>
          工作经验{{ details.experience }}年
        </view>
      </view>
      <view class="info_box"
      >
        <view>

          <view class="price">
            价格:{{ details.price }}元/小时
          </view>
        </view>


      </view>
      <view class="content">{{ details.name }}/{{ details.specialty }}</view>


      <view class="food-inrduc">

        <view class="inrduc-center" style="margin-top: 50upx;">
          <text class="online">——</text>
          <text class="txt" style="color: #000000;">预约信息</text>
          <text class="online">——</text>
          <text class="fuhao">▼</text>
        </view>

        <view class="form_list">
          <view class="time_box">
            <view class="chef_input_box">
                <input v-model="showDate" placeholder="请输入预约时间"/>
            </view>

            <view class="icon_box" @click="show = true">
              <image src="../../static/images/collect.png"/>
            </view>
          </view>


          <view class="chef_input_box">
            <input v-model="address" placeholder="请输入地址"/>
          </view>

          <view class="chef_input_box">
            <input  v-model="telPhone" placeholder="请输入联系电话"/>
          </view>
        </view>


        <u-picker mode="time" v-model="show" :params="params" @confirm="confirmTime">
        </u-picker>
      </view>



      <view class="food-step">
        <!-- 底部导航 -->
        <view class="goods_nav">

          <view class="btn">
            <button @click='appointChef' class="btn-left">立即预约</button>
            <button @click='goCart' class="btn-right">我的订单</button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>

import uniPopup from '@/components/uni-popup/uni-popup.vue';



import {
  user_join
} from '@/api/user_cart.js'

import {
  chef_detail,
  appointment_chef
} from '@/api/chef.js'
import UniIcons from "@/components/uni/uni-icons/uni-icons.vue";

export default {
  components: {
    UniIcons,
    uniPopup,
  },
  data() {
    return {
      showDate: '', //默认内容，可以是时间，也可以是提示文字
      params: { //参数配置，如果要显示时、分、秒，将对应的false改为true
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false
      },
      foodId: "",
      details: {},
      show: false,
      title: "",
      detailId: "",
      address:'',
      telPhone:'',
    }
  },
  onLoad(options) {
    this.detailId = options.id;
    this.getDetails();
  },


  methods: {
    confirmTime(e) {
      //可以将e在控制台打印出来看看
      this.showDate = e.year + '-' + e.month + '-' + e.day
    },



    cancel() {
      this.show = false
    },
    appointChef() {
      console.log("click")
      let params = {}
      params.chefId = this.detailId
      params.appointmentTime = this.showDate
      params.address= this.address
      params.telPhone= this.telPhone
      params.meals = 1
      appointment_chef(params).then(res => {
        if (res.code === '200') {
          uni.showToast({
            title: '预约成功',
            icon: 'none'
          })
          this.address=''
          this.telPhone=''
          this.showDate=''
        }
      })
    },

    getDetails() {
      let params = {}
      params.id = this.detailId
      chef_detail(params).then(res => {
        if (res.code === '200') {
          this.details = res.data
        }
      })
    },


    previewImg(imageUrl) {
      console.log(imageUrl)
      var images = [];
      images.push(imageUrl);
      console.log(images)
      uni.previewImage({
        current: 0,
        urls: images
      });
    },

    buttonClick(e) {
      let params = {}
      params.type = 1;
      params.foodId = this.foodId
      user_join(params).then(res => {
        if (res.code === '200') {
          uni.showToast({
            title: '加入成功',
            icon: 'none'
          })
        }
      })

    },
    goCart() {
      uni.navigateTo({
        url: '/pages/appointment/appointment'
      })
    }

  }
}
</script>

<style lang="scss">

.form_list{
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;

  .time_box{
    width: 90%;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .chef_input_box{
      width: 85%;
      height: 60upx;
      border: #8d8d8d 1upx solid;
      border-radius: 16upx;
      padding: 2upx 8upx;

      input{
        width: 100%;
        height: 60upx;
      }

    }
  }
  .icon_box{
    height: 60upx;
    width: 60upx;
    border-radius: 8upx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
    image{
      height: 48upx;
      width: 48upx;
    }

  }
  .chef_input_box{
    width: 90%;
    height: 60upx;
    border-radius: 16upx;
    padding: 2upx 8upx;
    border: #8d8d8d 1upx solid;

    input{
      width: 100%;
      height: 60upx;
    }
  }

}



.content{
  margin-top: 32rpx;
  margin-right: 32rpx;
  margin-left: 32rpx;
}

.info_box {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-top: 12upx;
  margin-left: 32rpx;
  font-size: 32upx;
  color: gray;
}

.items {
  width: 100%;
  display: flex;
  box-sizing: border-box;
  flex-wrap: wrap;
  font-family: "楷体",serif;

  .chef-head {
    position: relative;

    image {
      width: 750rpx;
      height: 550rpx;
      background-size: cover;
    }

    .food-name {
      position: absolute;
      bottom: -80rpx;
      left: 50%;
      margin-left: -37rpx;
      padding: 10rpx;
      width: 60rpx;
      background-color: rgba($color: #fff, $alpha: 0.81);
      opacity: 0.7;
      border-radius: 30rpx;
      text-align: center;

      .name-txt {
        padding: 13rpx 12rpx;
        border: 1rpx solid #000;
        font-size: 33rpx;
        border-radius: 20rpx;
        color: #000;
        line-height: 43rpx;
      }
    }
  }

  .food-inrduc {
    width: 100%;
    margin-bottom: 40rpx;
    color: #979797;

    .content {
      margin-left: 38rpx;
      text-indent: 2em;
    }
  }


  .goods_nav {
    position: fixed;
    display: flex;
    bottom: 0;
    width: 100%;
    background-color: #fff;
    left: 20%;

    .tab {
      display: flex;
      padding: 0 5px;
      font-size: 12px;

      .tab_item {

        margin: 15rpx 10px 0;

        .tab-btn {
          border: 0;


        }
      }
    }

    .btn {
      float: right;
      display: flex;
      width: 446rpx;
      height: 80rpx;
      margin: 5px 10px 5px 0;
      overflow: hidden;

      button {
        height: 80rpx;
        line-height: 80rpx;
        font-size: 14px;

        flex: 1;
      }

      button::after {
        border: none;
      }

      .btn-left {
        border-top-left-radius: 200rpx;
        border-bottom-left-radius: 200rpx;
        background-color: #ff0000;
        color: #fff;
      }

      .btn-right {
        border-top-right-radius: 200rpx;
        border-bottom-right-radius: 200rpx;
        background-color: #ffa200;
        color: #fff;
      }
    }
  }

  .inrduc-center {
    text-align: center;
    color: orange;

    .txt {
      font-size: 35rpx;
      font-weight: 520;
      padding: 0 20rpx;
    }

    .fuhao {
      display: block;
    }

  }


}
</style>